home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7186 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C constant expression declarations
  5. Date: 17 Feb 96 21:28:51 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.824592531@rscernix>
  8. References: <31229735.41C67EA6@isi.com> <4fvl5cINN94q@keats.ugrad.cs.ubc.ca> <4g2nha$ksa@sun001.spd.dsccc.com> <4g3fkeINNoj7@keats.ugrad.cs.ubc.ca>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4g3fkeINNoj7@keats.ugrad.cs.ubc.ca> c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
  13.  
  14. >Parentheses are intended to override operator precedence, and to occasionally
  15. >make a complex expression clearer to someone reading them; a proverbial icing
  16. >on the cake of sorts.  
  17. >
  18. >if (x == 3 || y > 4 && z < 5)  
  19. >
  20. >is easier to read than
  21. >
  22. >if ((x == 3) || ((y > 4) && (z < 5))) 
  23.  
  24. But 
  25.  
  26. if (x == 3 || (y > 4 && z < 5))
  27.  
  28. is even easier to read.  An expression with too many operators becomes
  29. difficult to read in the total absence of parentheses (especially if
  30. you don't have an operator precedence table handy :-)  Unfortunately, the
  31. right amount of (otherwise) unnecessary parentheses needed to make a
  32. complex expression readable differs from person to person.
  33.  
  34. Here's a very perfid trap, waiting to catch the unsuspecting programmer:
  35.  
  36. if (a & mask == b)
  37.  
  38. This is a known deficiency of the C operator precedence, deeply rooted
  39. in the history of the C language (once upon a time, & and && were only
  40. one operator).
  41.  
  42. Just my $0.02,
  43. Dan
  44. --
  45. Dan Pop
  46. CERN, CN Division
  47. Email: danpop@mail.cern.ch 
  48. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  49.